<!DOCTYPE html>
<html>
<head>
    <title>Unit tests for bitjs.io.ByteStream and bitjs.io.ByteBuffer</title>
    <script src="muther.js"></script>
    <script src="io.js"></script>
</head>
<body>
<script>
    var buffer;
    muther.go({
      setUp: function() {
        buffer = new bitjs.io.ByteBuffer(10);
      },
      tests: [
        function testWriteNumberThenRead() {
          buffer.writeNumber(1234, 4);
          var stream = new bitjs.io.ByteStream(buffer.data);
          muther.assertEquals(1234, stream.peekNumber(4));
        },
        function testWriteUnsignedByteThenRead() {
          buffer.writeNumber(192, 1);
          var stream = new bitjs.io.ByteStream(buffer.data);
          muther.assertEquals(192, stream.readNumber(1));
        },
        function testWriteSignedByteThenRead() {
          buffer.writeSignedNumber(-120, 1);
          var stream = new bitjs.io.ByteStream(buffer.data);
          muther.assertEquals(-120, stream.readSignedNumber(1));
        },
        function testWriteSignedPositiveNumberThenRead() {
          buffer.writeSignedNumber(1234, 4);
          var stream = new bitjs.io.ByteStream(buffer.data);
          muther.assertEquals(1234, stream.readSignedNumber(4));
        },
        function testWriteSignedNegativeNumberThenRead() {
          buffer.writeSignedNumber(-128, 1);
          var stream = new bitjs.io.ByteStream(buffer.data);
          muther.assertEquals(-128, stream.readSignedNumber(1));
        },
        function testWriteOverflowUnsigned() {
          var passed = false;
          try {
              buffer.writeNumber(256, 1);
          } catch(e) {
              passed = true;
          }
          muther.assert(passed);
        },
        function testWriteOverflowSignedPositive() {
          var passed = false;
          try {
              buffer.writeSignedNumber(128, 1);
          } catch(e) {
              passed = true;
          }
          muther.assert(passed);
        },
        function testWriteOverflowSignedNegative() {
          var passed = false;
          try {
              buffer.writeSignedNumber(-129, 1);
          } catch(e) {
              passed = true;
          }
          muther.assert(passed);
        }
      ]
    });
</script>
</body>
</html>
